/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DA;

import BE.Curso;
import BE.Horario;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author jmj
 */
public class HorarioDA {
      public static List<Horario> FindAll(){
        Session hbsession = HUtil.getSessionFactory().openSession();
        try{
            Query query = hbsession.createQuery("FROM Horario");
            
            hbsession.close();
            return query.list();
            
            
        }catch(Exception ex){
            hbsession.close();
            return null;
        }
    }
      
    public static List<Horario> FindByCurso(int idCurso){
        Session hbsession = HUtil.getSessionFactory().openSession();
        
        
        
        
        try{
            Query query = hbsession.createQuery("FROM Horario WHERE idCurso = :idCurso");
            
            query.setParameter("idCurso", idCurso);
            
            hbsession.close();
            return query.list();
            
            
        }catch(Exception ex){
            hbsession.close();
            return null;
        }
        
    }
      public static List<Horario> FindByCurso(Curso curso){
        Session hbsession = HUtil.getSessionFactory().openSession();
        
        int idCurso = curso.getIdCurso();
        
        
        try{
            Query query = hbsession.createQuery("FROM Horario WHERE idCurso = :idCurso");
            
            query.setParameter("idCurso", idCurso);
            
            hbsession.close();
            return query.list();
            
            
        }catch(Exception ex){
            hbsession.close();
            return null;
        }
        
    }   
}
